/**
 * 
 */
package cn.suse.android.adapter;

import java.util.List;

import cn.suse.android.R;
import cn.suse.android.entity.Group;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author liubin
 * Create DateTime:Oct 16, 2012 6:16:39 PM
 * Description:
 * @Version: 1.0.0
 */
public class GroupAdapter extends BaseAdapter {

	private List<Group> lists;
	private Context context;
	
	public GroupAdapter(List<Group> lists, Context context) {
		super();
		this.lists = lists;
		this.context = context;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lists == null?0:lists.size();
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return lists == null?null:lists.get(position);
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder holder = null;
		View view =convertView;
		if(view == null){
			view = LayoutInflater.from(context).inflate(R.layout.group_listitem, null);
			holder = new Holder();
			holder.catalogTextView = (TextView)view.findViewById(R.id.catalog);
			holder.group_nameTextView = (TextView)view.findViewById(R.id.group_name);
			view.setTag(holder);
		}else{
			holder = (Holder) view.getTag();
		}
		holder.catalogTextView.setText(lists.get(position).getCatalog());
		holder.group_nameTextView.setText(lists.get(position).getName());
		return convertView;
	}
	
	public List<Group> getLists() {
		return lists;
	}

	public void setLists(List<Group> lists) {
		this.lists = lists;
		this.notifyDataSetChanged();
	}
	private static class Holder{
		TextView group_nameTextView;
		TextView catalogTextView;
	} 
}
